package com.carnation.servlet;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.carnation.bean.MenuTree;
import com.carnation.utils.MenuRead;
import com.google.gson.Gson;

public class TreeMenuServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;
	private Logger logger = Logger.getLogger(TreeMenuServlet.class);

	protected void doPost(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse){
		doGet(httpServletRequest, httpServletResponse);
	}
	
	protected void doGet(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse){
		MenuRead menuRead = new MenuRead();
		MenuTree menuTree = menuRead.getMenuTree();
		Gson gson = new Gson();
		try {
			httpServletResponse.setCharacterEncoding("UTF-8");
			httpServletResponse.getWriter().write(gson.toJson(menuTree));
			httpServletResponse.getWriter().close();
		} catch (IOException e) {
			logger.error("获取菜单目录树失败",e);	
		}
		
	}
}
